{include file="public/head" /}
  
  <body>
    <div class="x-body">
        <form class="layui-form" style="margin-left: 80px;" >
            <div class="layui-form-item">
                <label for="L_community_id" class="layui-form-label">
                    <span class="x-red">*</span>所属小区:
                </label>
                <div class="layui-input-inline" style="width: 300px;">
                    <select name="community_id" lay-filter="commname"  lay-verify="required" id="L_community_id">
                        <option value="">所属小区</option>
                        {foreach $communitylist as $com}
                        <option value="{$com.community_id}">{$com.community_name}</option>
                        {/foreach}
                      </select>
                </div>
            </div>    
            
            <div class="layui-form-item">
                <label for="L_business_type" class="layui-form-label">
                    <span class="x-red">*</span>业务类型:
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="L_business_type" name="business_type" required="" lay-verify="required"
                    autocomplete="off" class="layui-input"  style="width: 300px;">
                </div>
            </div>
            <div class="layui-form-item">
                <label for="L_company" class="layui-form-label">
                    <span class="x-red">*</span>付款单位:
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="L_company" name="company" required="" lay-verify="required"
                    autocomplete="off" class="layui-input" style="width: 300px;">
                </div>
            </div>
            <div class="layui-form-item">
              <label for="L_money" class="layui-form-label">
                  <span class="x-red">*</span>付款金额:
              </label>
              <div class="layui-input-inline">
                  <input type="text" id="L_money" name="money" required="" lay-verify="required"
                  autocomplete="off" class="layui-input"  style="width: 300px;">
              </div>
          </div>
          <div class="layui-form-item">
              <label for="L_phone" class="layui-form-label">
                  <span class="x-red">*</span>联系电话:
              </label>
              <div class="layui-input-inline">
                  <input type="text" id="L_phone" name="phone" required="" lay-verify="required"
                  autocomplete="off" class="layui-input" style="width: 300px;">
              </div>
          </div>
          <div class="layui-form-item">
            <label for="L_paytype" class="layui-form-label">
                <span class="x-red">*</span>支付方式:
            </label>
            <div class="layui-input-inline" style="width: 300px;">
                <select name="paytype" lay-filter="L_paytype" id="L_paytype" lay-verify="required">
                    <option value="">支付方式</option>
                    {foreach $paytype as $pay}
                    <option value="{$pay.name}">{$pay.name}</option>
                    {/foreach}
                </select>
            </div>
        </div>  
            <div class="layui-form-item">
                <label for="L_status" class="layui-form-label">
                    <span class="x-red">*</span>支付状态:
                </label>
                <div class="layui-input-inline" style="width: 300px;">
                    <select name="status1" lay-filter="L_status" id="L_status" lay-verify="required">
                        <option value="1">已支付</option>
                        
                        <option value="2">未支付</option>
                       
                    </select>
                </div>
            </div> 
            <div class="layui-form-item">
                <label for="L_repass" class="layui-form-label">
                </label>
                <button  class="layui-btn" lay-filter="add" lay-submit="">
                    添加账单
                </button>
            </div>
      </form>
    </div>
    <script>
        layui.use('laydate', function(){
            var laydate = layui.laydate;
            
            //执行一个laydate实例
            laydate.render({
            elem: '#start' //指定元素
            ,format: 'yyyyMMdd'
            });

            //执行一个laydate实例
            laydate.render({
            elem: '#end' //指定元素
            ,format: 'yyyyMMdd'
            });
        });
        
        
       
    </script>
    <script>
        layui.use(['form'], function() {
            $ = layui.jquery;
            var form = layui.form,layer = layui.layer;
            form.on('select(commname)', function(f){
                var url = "{:url('admin/Roominfo/fetchdata')}"
                $.post(url, {community_id: f.value, type: 4}, function(data) {
                $('#address').html("")
                var option = "<option value=''>选择房间号</option>"
                $('#address').append(option)
                for (var i = 0; i < data.length; i++) {
                    option = "<option value='" + data[i] + "'>" + data[i] + "</option>"
                    $('#address').append(option)
                }
                form.render('select')
                })
            })
            
            form.on('submit(add)', function(data){
                console.log(data.field);
                
                $.ajax({  
                  type: 'post',  
                  url: "{:url('cashieradd')}", 
                  data: {  
                      community_id:data.field.community_id,
                      business_type:data.field.business_type,
                      company:data.field.company,
                      money:data.field.money,
                      phone:data.field.phone,
                      paytype:data.field.paytype,
                      status:data.field.status1
                  },  
                  success: function(data){ 
                    if(data=='ok'){
                      layer.alert("添加成功", {icon: 6},function () {
                            // 获得frame索引
                            var index = parent.layer.getFrameIndex(window.name);
                            //关闭当前frame
                            parent.layer.close(index);
                            window.parent.location.reload();
                        });
                    }else if(data=='error'){
                      layer.msg('添加失败');
                    }
                  }  
              });    
                //发异步，把数据提交给php
                /*layer.alert("增加成功", {icon: 6},function () {
                    // 获得frame索引
                    var index = parent.layer.getFrameIndex(window.name);
                    //关闭当前frame
                    parent.layer.close(index);
                });*/
                return false;
              });
        })
      </script>
    <script>var _hmt = _hmt || []; (function() {
        var hm = document.createElement("script");
        hm.src = "https://hm.baidu.com/hm.js?b393d153aeb26b46e9431fabaf0f6190";
        var s = document.getElementsByTagName("script")[0];
        s.parentNode.insertBefore(hm, s);
      })();</script>
  </body>

</html>